<?php
/**
	数据推送文件，接口执行文件
**/
	header('content-type:text/html;charset=utf-8');	
	ini_set('date.timezone','Asia/Shanghai');
	require_once $_SITE_PATH_ . "m/m_information.php";
	require_once $_SITE_PATH_ . "m/m_tasklist.php";
	require_once 'UpFile_ApiClient.class.php';
	
	$code=isset($_POST['code'])?$_POST['code']:'';
	$order_sn=isset($_POST['order_sn'])?$_POST['order_sn']:'';
	$taskid=isset($_POST['taskid'])?$_POST['taskid']:'';
	
	/* echo $code;
	exit; */
	if(empty($code) || empty($order_sn))
		{
			echo 'code 或 order_sn 不能为空！';
			exit;
		}
		
	$m_information=new m_information();
	$m_tasklists=new m_tasklist();

	$m_information->_ssql='select `code`,`is_upfile` from information where `is_upfile`=1 and `code` in('.$code.') and c_status="1" and p_status="1" order by `id` asc limit 0,10 ';
	$m_information->_ssql='select `code`,`is_upfile` from information where `is_upfile`=0 and `code` in('.$code.') order by `id` asc limit 0,1 ';
	
	$upfile=$m_information->getArray($m_information->query());
	//echo $m_information->_ssql;
	//echo '<br/>';
	//var_dump($upfile);
	//var_dump($code);
	$count=$m_information->getCount(' `is_upfile`=1 and `code` in('.$code.') and c_status="1" and p_status="1" ');
		$count=$m_information->getCount(' `is_upfile`=0 and `code` in('.$code.') ');
	if($count<=0)
		{
			echo '文件状态数据为空！';
			exit;
		}
		else
			{
				for($i=0;$i<$count;$i++)
					{
						$upfile[$i]->order_sn=$order_sn;
					}
			}
	
	
	$auth='tjiePjfjvnyGUuyMFEXVPmsewokCauuZ';
	$json_arr=array('data'=>$upfile,'count'=>$count);
	$json_arr=json_encode($json_arr);
	$time=time();
	$data=array('flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>$time,'charset'=>'utf-8','ver'=>1,'file_status'=>$json_arr);
	/* var_dump($data);
	exit; */
	$url='http://120.86.185.197/index.php/openapi/rpc/service';
	$api=new UpFile_ApiClient();
	$result=$api->DoRequest($url,$auth,$data);
	echo '返回结果为：';
	var_dump($result);
	/* echo 'result:';
var_dump($result); */
//exit;
	if(strtoupper($result['info'])=='SUCCESS')
		{
			$m_tasklist->_ssql='update tasklist set `ts_flag`="1",excuflag="1" where `id`='.$taskid;
			$m_tasklist->query();
			//写入日志 fopen();
			echo '成功推送数据！';
			exit;
		}
		elseif(strtoupper($result['info'])=='FAILED')
			{
				echo '推送数据失败！';
				exit;
			}
			else
				{
					//echo '发生异常错误！';
					exit;
				}
	
	
	
	
	
	
	

?>